// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FeedWiring.cs" company="Open Trader">
//   Copyright (c) David Denis (david.denis@systemathics.com)
// </copyright>
// <summary>
//   |  Open Trader - The Open Source Systematic Trading Platform
//   |
//   |  This program is free software: you can redistribute it and/or modify
//   |  it under the terms of the GNU General Public License as published by
//   |  the Free Software Foundation, either version 2 of the License, or
//   |  (at your option) any later version.
//   |
//   |  This program is distributed in the hope that it will be useful,
//   |  but WITHOUT ANY WARRANTY; without even the implied warranty of
//   |  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   |  GNU General Public License for more details.
//   |
//   |  You should have received a copy of the GNU General Public License
//   |  along with this program.  If not, see http://www.gnu.org/licenses
//   |
//   |  Up to date informations about Open Trader can be found at :
//   |    http://opentrader.org
//   |    http://opentrader.codeplex.com
//   |
//   |  For professional services, please visit us at :
//   |    http://www.systemathics.com
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Org.OpenTrader.Framework.Forge
{
    #region Using Directives

    using System;

    using Org.OpenTrader.Framework.Forge.Interfaces;
    using Org.OpenTrader.Framework.LiveObjects.Interfaces;

    #endregion

    /// <summary>
    /// The feed wiring.
    /// </summary>
    public class FeedWiring : Wiring, IFeedWiring
    {
        #region Constants and Fields

        /// <summary>
        /// Two FeedWiring are considered equal if comparers are equal.
        /// </summary>
        private readonly string comparer;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="FeedWiring"/> class.
        /// </summary>
        /// <param name="instrumentID">
        /// The instrument id.
        /// </param>
        /// <param name="pluginId">
        /// The plugin id.
        /// </param>
        /// <param name="subscriptionConfiguration">
        /// The subscription configuration.
        /// </param>
        public FeedWiring(Guid instrumentID, Guid pluginId, IConfiguration subscriptionConfiguration)
        {
            this.InstrumentID = instrumentID;
            this.PluginID = pluginId;
            this.SubscriptionConfiguration = subscriptionConfiguration;
            this.comparer = string.Format("{0}:{1}", this.PluginID, subscriptionConfiguration);
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="FeedWiring"/> class.
        /// </summary>
        public FeedWiring()
        {
            this.comparer = string.Empty;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Gets SubscriptionConfiguration.
        /// </summary>
        public IConfiguration SubscriptionConfiguration { get; set; }

        #endregion

        #region Public Methods

        /// <summary>
        /// The equals.
        /// </summary>
        /// <param name="obj">
        /// The obj.
        /// </param>
        /// <returns>
        /// The equals.
        /// </returns>
        public override bool Equals(object obj)
        {
            if (obj is FeedWiring)
            {
                var fobj = obj as FeedWiring;
                return fobj.comparer.Equals(this.comparer);
            }

            return false;
        }

        /// <summary>
        /// The get hash code.
        /// </summary>
        /// <returns>
        /// The get hash code.
        /// </returns>
        public override int GetHashCode()
        {
            return this.comparer.GetHashCode();
        }

        /// <summary>
        /// The to string.
        /// </summary>
        /// <returns>
        /// The to string.
        /// </returns>
        public override string ToString()
        {
            return this.comparer;
        }

        #endregion

        #region Implemented Interfaces

        #region IWiring

        /// <summary>
        /// The clone.
        /// </summary>
        /// <returns>
        /// </returns>
        public override IWiring Clone()
        {
            return new FeedWiring(this.InstrumentID, this.PluginID, this.SubscriptionConfiguration);
        }

        #endregion

        #endregion
    }
}